package controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import pojo.HealthTip;
import service.HealthTipService;

import java.util.List;

@Controller
@CrossOrigin(origins = "*")
@RequestMapping("/healthTip")
@Api(tags = "健康小贴士管理接口", description = "提供健康小贴士相关的增删改查功能")
public class HealthTipController {

    @Autowired
    private HealthTipService healthTipService;

    @GetMapping("/findAll")
    @ResponseBody
    @ApiOperation(value = "查询所有健康小贴士", notes = "获取系统中所有健康小贴士的信息")
    public List<HealthTip> findAll() {
        return healthTipService.findAll();
    }

    @GetMapping("/findById")
    @ResponseBody
    @ApiOperation(value = "根据ID查询健康小贴士", notes = "通过ID获取具体健康小贴士信息")
    @ApiImplicitParam(name = "id", value = "健康小贴士ID", required = true, dataType = "Integer", paramType = "query")
    public HealthTip findById(@RequestParam Integer id) {
        return healthTipService.findById(id);
    }

    @PostMapping("/add")
    @ResponseBody
    @ApiOperation(value = "添加健康小贴士", notes = "新增健康小贴士信息到系统")
    public int add(@RequestBody HealthTip healthTip) {
        return healthTipService.add(healthTip);
    }

    @PostMapping("/update")
    @ResponseBody
    @ApiOperation(value = "更新健康小贴士信息", notes = "根据ID更新健康小贴士信息")
    public int update(@RequestBody HealthTip healthTip) {
        return healthTipService.update(healthTip);
    }

    @PostMapping("/delete")
    @ResponseBody
    @ApiOperation(value = "删除健康小贴士", notes = "根据ID删除健康小贴士信息")
    @ApiImplicitParam(name = "id", value = "健康小贴士ID", required = true, dataType = "Integer", paramType = "query")
    public int delete(@RequestParam Integer id) {
        return healthTipService.deleteHealthTip(id);
    }
}